package com.huyanqi.core.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.skyway.spring.util.dao.JpaDao;

import com.huyanqi.core.Page;

/**
 * 
 * <p>Title: BaseDAO.java</p>
 * 
 * <p>Description: 抽象基础泛型DAO interface</p>
 * 
 * <p>Datetime: 2011-12-25 下午5:40:07</p>
 *
 * @company 成都映潮科技有限公司
 * 
 * @author <a href="mailto:liwei@sunsharp.cn">p.k.ripper</a>
 *
 */
public interface BaseDAO<T,PK extends Serializable> extends JpaDao<T>{
	/**
	 * 保存实体对象
	 * @param e
	 * @return T
	 * @throws Exception
	 */
	T saveEntity(T e) throws Exception;
	/**
	 * 更新实体对象 
	 * @param e
	 * @return T
	 * @throws Exception
	 */
	T updateEntity(T e) throws Exception;
	/**
	 * 删除实体对象
	 * @param e T
	 * @throws Exception
	 */
	void deleteEntity(T e) throws Exception;
	/**
	 * 根据ID删除实体对象
	 * @param id
	 * @throws Exception
	 */
	void deleteEntity(final PK id) throws Exception;
	/**
	 * 根据ID查找实体对象
	 * @param id
	 * @return T
	 * @throws Exception
	 */
	T findEntityById(final PK id) throws Exception;
	
	/**
	 * 按ID查询多个对象
	 * 
	 * @param ids
	 * @return
	 */
	public List<T> findByIds(final Collection<PK> ids) throws Exception;
	/**
	 * 批量增加
	 * @param e
	 * @throws Exception
	 */
	void batchSave(Collection<T> e) throws Exception;
	/**
	 * 批量修改
	 * @param e
	 * @throws Exception
	 */
	void batchUpdate(Collection<T> e) throws Exception;
	/**
	 * 批量删除
	 * @param e
	 * @throws Exception
	 */
	void batchDelete(Collection<T> e) throws Exception;

	/**
	 * 根据id批量删除
	 * @param e
	 * @param ids
	 * @throws Exception
	 */
	void batchDelete(final PK... ids) throws Exception;		
	
	public List<T> findByProperty(Map<String, Object> values) throws Exception;
	
	public List<T> findByPropertyLike(String propertyName, Object value) throws Exception;

	public List<T> findByProperty(String propertyName, Object value) throws Exception;
	
	public List<T> findByCriteria(Criterion... criterions) throws Exception;
	
	public List<T> findByCriteria(Order[] order,Criterion... criterions) throws Exception;
	
	<X> X findUniqueCountByHql(final String hql, final Object... parameters) throws Exception;
	
	Page<T> findPage(final Page<T> page, final String hql,final Object... parameters) throws Exception;
	
	List<Object> findPageBySQL(final Page<T> page,String sql,Object...parameters)throws Exception;
	
	Object findSingleResultBySQL(String sql,Object...parameters)throws Exception;
	
	Page<T> findPageByNameQuery(final Page<T> page,final String queryName,final Object... parameters) throws Exception;
	
	public Page<T> findAllByPage(final Page<T> page,final Criterion... criterions) throws Exception;

	public Page<T> findAllByPageDistinct(final Page<T> page,final Criterion... criterions) throws Exception;
}
